package org.idea.spring.aop.version2.bean;

import org.idea.spring.aop.version2.service.IAspectConfig;
import org.idea.spring.aop.version2.service.IAspectDemo;

import java.util.regex.Pattern;

/**
 * 作用 判断某个对象是否匹配切面的规则
 * @Author linhao
 * @Date created in 12:30 下午 2021/5/7
 */
public class AdviceHelper {


    private String aspectNameKey;

    private Pattern pointCutClassPattern;

    public Pattern getPointCutClassPattern() {
        return pointCutClassPattern;
    }

    public void setPointCutClassPattern(Pattern pointCutClassPattern) {
        this.pointCutClassPattern = pointCutClassPattern;
    }


    public boolean isMatchTarget(String className) {
        return this.getPointCutClassPattern().matcher(className).matches();
    }

    public String getAspectNameKey() {
        return aspectNameKey;
    }

    public void setAspectNameKey(String aspectNameKey) {
        this.aspectNameKey = aspectNameKey;
    }

    public static void main(String[] args) {
        IAspectDemo iAspectDemo = new IAspectDemo();
        AdviceHelper adviceHelper = new AdviceHelper();
        adviceHelper.setPointCutClassPattern(Pattern.compile("org.idea.spring.aop.version2.service.*"));
        boolean status = adviceHelper.getPointCutClassPattern().matcher(iAspectDemo.getClass().getName()).matches();
        System.out.println(status);
    }
}
